package com.util.concurrent.lock;

import org.junit.Test;

import java.util.concurrent.locks.StampedLock;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-07-25 15:58:36
 */
public class LockTest {

    @Test
    public void test3() {
        StampedLock lock = new StampedLock();

        long l = lock.writeLock();
        System.out.println(l);

        long l1 = lock.tryConvertToWriteLock(l);
        System.out.println(l1);
    }

    @Test
    public void test2() {
        StampedLock lock = new StampedLock();

        long l = lock.readLock();
        System.out.println(l);

        long l1 = lock.tryConvertToWriteLock(l);
        System.out.println(l1);
    }

    @Test
    public void test1() {
        LockVo vo = LockVo.builder().id(1).name("Hello").build();

        Cache<LockVo> cache = new Cache<>();
        cache.write("1", vo);

        LockVo read = cache.read("1", LockVo.class);
        System.out.println(read);
    }
}
